﻿/****** Object:  UserDefinedFunction [dbo].[F_MyDiscount]    Script Date: 04/07/2011 00:45:33 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE FUNCTION [dbo].[F_MyDiscount]
(
@Uid int = 0
,@ProductId int
)
RETURNS  float
AS
BEGIN
declare @MyDiscount float
select  top 1
	@MyDiscount = a.discount
	from Product_Discount as a  inner join User_UserInLevel as b
	on a.LevelId = b.LevelId
where a.ProductId = @ProductId  and b.uid = @Uid and a.IsDiscount =1
order by discount asc
return @myDiscount

end


GO

